package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.dto.InStoreDTO;
import net.wanho.service.InStoreService;
import net.wanho.vo.AjaxResult;
import net.wanho.vo.BuyListVo;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/instore")
@RequiredArgsConstructor
public class InstoreController {
    private final InStoreService inStoreService;

    /**
     *  入库列表
     */
    @GetMapping("/instore-page-list")
    public AjaxResult instorePageList(BuyListVo buyListVo,
                                      @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                      @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return AjaxResult.success(inStoreService.getPageList(buyListVo, pageNum, pageSize));
    }

    /**
     * 入库确认
     */
    @PutMapping("/instore-confirm")
    public AjaxResult instoreConfirm(@RequestBody InStoreDTO inStoreDTO) {
        inStoreService.updatePurchaseById(inStoreDTO);
        return AjaxResult.success(null, "入库成功");
    }

    /**
     * 导出数据
     */
    @GetMapping("/exportTable")
    public AjaxResult exportTable(BuyListVo buyListVo,
                                  @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return AjaxResult.success(inStoreService.getPageList(buyListVo, pageNum, pageSize).getResultList());
    }
}
